import timLogin from '@/utils/timLogin.js'
export default {
  data() {
    return {
      bookid: '', //预约订单id
      madAppList: {}, //预约详情
      madappStatus: '', //状态
      xedColorList: {
        outerColour: [{
          colorCoding: '',
          color: ''
        }],
        inColour: [{
          colorCoding: '',
          color: '',
          neiColor: [{}]
        }]
      }, //选择的颜色集合
      qPriceList: [], //报价list
      qPriceLength: 0, //报价长度
      brandid: 9, //品牌id
      showPage: false
    }
  },
  onLoad(caridxix) {
    this.bookid = caridxix.id
    this.GetCarFindDetailsById()
  },
  filters: {
    million(value) { //过万处理
      let num
      if (value > 9999) { //大于9999显示x.xx万
        num = ((value / 1000) / 10).toFixed(2) + '万'
      } else if (value <= 9999 && value >= -9999) {
        num = value + '元'
      } else if (value < -9999) { //小于-9999显示-x.xx万
        num = -((Math.abs(value) / 1000) / 10).toFixed(2) + '万'
      }
      return num
    }
  },
  methods: {
    getCont(getList){
      console.log(getList)
      this.$store.commit('news/createConversationActive', {
			  user: getList.store_Name, //店铺名称
			  img: getList.store_Topimg, //店铺头像
			  lastTime: '', //
			  userId: getList.store_Id, //店铺id
			  conversationID: 'C2C',
      })
      this.$store.commit('news/setCardInfo', {
			  imgSrc: 'https://files.yzsheng.com/goodimg/brandimg/'+this.brandid+'.png',
			  name: getList.trueName,
			  price: getList.quoted_Price,
			  type: 'resaleCar',
        goPage: '2'
      })
      uni.navigateTo({
			  url: '/pages_common/contactSeller/contactSeller?user=' + getList.trueName + '&pageId=' + this.madAppList.id+'&tab=2'
      })
    },
    //一成首付在线咨询
    contact(getList){
		  if (this.$store.state.isSDKReady) {
		    this.getCont(getList)
		  } else {
		    timLogin(() => {
		      this.getCont(getList)
		    })
		  }
    },
    returnTime(time) {
		  if (time) {
		    return time.split('T')[0] + ' ' + time.split('T')[1]
		  }
    },
    // 客服电话
    onNavigationBarButtonTap(e) {
      uni.makePhoneCall({
        phoneNumber: this.$store.state.serviceNumber.number
      })
    },
    //详情
    async GetCarFindDetailsById() {
      try {
        const res = await this.$api.order.GetCarFindDetailsById({
          id: this.bookid
        })
        this.showPage = true
        this.madAppList = res.data
        this.xedColorList = JSON.parse(res.data.colour)
        this.xedColorList.inColour = this.filtercolor(this.xedColorList.inColour) //内试颜色
        console.log(this.xedColorList)

        //预约状态(0、询价中(里面有两个状态，待报价，待确认)  2、已完成  3、关闭)
        if (res.data.status === 0) {
          if (res.data.quotedPriceList.length === 0) {
            this.madappStatus = '待报价'
          } else {
            this.madappStatus = '待确认'
          }
        } else if (res.data.status === 2) {
          this.madappStatus = '已完成'
        } else {
          this.madappStatus = '关闭'
        }
        this.qPriceList = res.data.quotedPriceList
        this.qPriceLength = this.qPriceList.length
        this.brandid = this.madAppList.brand_Id

      } catch (err) {}
    },
    //分割 内饰 颜色
    filtercolor(data) {
      data.forEach(item => {
        //如果颜色等于一个就不用分割，大于一个就分割颜色
        var arr = item.colorCoding.split('/')
        item.neiColor = arr
      })
      return data
    },
    //复制到剪切板
    copyClick(value) {
      uni.setClipboardData({
        data: value
      })
    },
    // 拨打电话
    mobileclick(e) {
      uni.makePhoneCall({
        phoneNumber: e
      })
    },
    mobileiphone(e) {
      uni.makePhoneCall({
        phoneNumber: e
      })
    },
    //确认报价
    qurbjClick(typeid,item) {
      console.log(typeid,item)
      this.SetQuoted(typeid)
    },

    async SetQuoted(typeid) {
      try {
        const res = await this.$api.order.SetQuoted({
          id: typeid
        })
        this.madAppList = res.data
        if (res.code === 200) {
          this.GetCarFindDetailsById()
        }

      } catch (err) {}
    },
  }
}
